﻿using Application.AppService.EIAppService;
using Application.AppService.ERAppService;
using AutoMapper;
using Domain;
using Domain.Entity;
using EFCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
using System.Text.Json;

namespace UI.Controllers.RecruitmentManagement_招聘管理_.Interview_management_面试管理_
{
	public class EIController : Controller
	{
		private readonly IMapper mapper;
		private readonly IEIAppService eIAppService;
		private readonly IERAppService eRAppService;
		private readonly IDistributedCache distributedCache;
		private readonly ILogger<EIController> logger;

		public EIController(IMapper mapper, IEIAppService eIAppService, IERAppService eRAppService, IDistributedCache distributedCache, ILogger<EIController> logger)
		{
			this.mapper = mapper;
			this.eIAppService = eIAppService;
			this.eRAppService = eRAppService;
			this.distributedCache = distributedCache;
			this.logger = logger;
		}
		public IActionResult Index()
		{
			return View();
		}
		public IActionResult Index1()
		{
			return View();
		}
		[HttpPost("FYEI")]
		public async Task<IActionResult> FYEI(int page, int pageSize)
		{
			//string key = "Book" + id;//缓存的键名
			//EIFenYe eiFenYE = null;
			//string s = await distributedCache.GetStringAsync("eiFenYE");
			////Book book = memoryCache.Get<Book>(key); //根据键去缓存取数据
			//if (s == null)
			//{
			//	//第1次，从数据库查
			//	logger.LogInformation("从数据库查询");
			//	eiFenYE = eIAppService.DateEIAsync(page, pageSize,1);
			//	var opt = new DistributedCacheEntryOptions();
			//	opt.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(10);
			//	await distributedCache.SetStringAsync("eiFenYE", JsonSerializer.Serialize(eiFenYE), opt);
			//}
			//else
			//{
			//	//不是第1次了
			//	logger.LogInformation("从缓存中获取");
			//	eiFenYE = JsonSerializer.Deserialize<EIFenYe>(s);
			//}
			//return Json(book);
			EIFenYe eiFenYE = eIAppService.DateEIAsync(page, pageSize, 1);
			return Json(eiFenYE);
		}
		[HttpPost("UpdateEI")]
		public  async Task<IActionResult> UpdateEI(EI ei)
		{
			bool rs =await eIAppService.UpdateEIAsync(ei);
			return Json(rs);
		}
		[HttpPost("UpdateERSS")]
		public async Task<IActionResult> UpdateERSS(ER er)
		{
			bool rs = await eRAppService.UpdateERSAsync(er);
			return Json(rs);
		}
		[HttpPost("DeleteER")]
		public async Task<IActionResult> DeleteER(int id)
		{
			bool rs = await eRAppService.DeleteERAsync(id);
			return Json(rs);
		}
		[HttpPost("DeleteEI")]
		public async Task<IActionResult> DeleteEI(int id)
		{
			bool rs = await eIAppService.DeleteEIAsync(id);
			return Json(rs);
		}
		[HttpPost("UpdateEIS")]
		public async Task<IActionResult> UpdateEIS(EI ei)
		{
			bool rs = await eIAppService.UpdateEISAsync(ei);
			return Json(rs);
		}
	}
}
